//
//  EditCharteredOrderNextViewController.m
//  didacar
//
//  Created by Yang Yuexia on 15/12/7.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "EditCharteredOrderNextViewController.h"
#import "EditCharteredOrderPreviewViewController.h"

@interface EditCharteredOrderNextViewController ()<UITextViewDelegate>

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *customView_layout_top;

@property (weak, nonatomic) IBOutlet UIView *customerView;

@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;

@property (weak, nonatomic) IBOutlet UITextField *nameTextField;

@property (weak, nonatomic) IBOutlet UITextView *textView;

@property (weak, nonatomic) IBOutlet UILabel *placeHolderLabel;

@property (weak, nonatomic) IBOutlet UIButton *nextButton;

- (IBAction)nextButtonAction:(id)sender;

@end

@implementation EditCharteredOrderNextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"填写包车订单";
    self.textView.delegate = self;
    
    self.nextButton.layer.cornerRadius = 4.0;
    self.nextButton.layer.masksToBounds = YES;
}

#pragma mark ---- UITextViewDelegate ----

- (void)textViewDidChange:(UITextView *)textView{
    if (textView.text.length == 0) {
        self.placeHolderLabel.text = @"例如，中途需要去一趟软件园接人";
    }else{
        self.placeHolderLabel.text = @"";
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSString *temp = [textView.text stringByReplacingCharactersInRange:range withString:text];
    if (temp.length > 100) {
        textView.text = [temp substringToIndex:100];
        self.placeHolderLabel.text = @"";
        return NO;
    }
    return YES;
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    [self.view layoutIfNeeded];
    [UIView animateWithDuration:0.3 animations:^{
        self.customView_layout_top.constant = -50;
        [self.view layoutIfNeeded];
    }];
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    [self.view layoutIfNeeded];
    [UIView animateWithDuration:0.3 animations:^{
        self.customView_layout_top.constant = 0;
        [self.view layoutIfNeeded];
    }];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.textView resignFirstResponder];
    [self.nameTextField resignFirstResponder];
}

#pragma mark ---- 下一步 ----
- (IBAction)nextButtonAction:(id)sender
{
    EditCharteredOrderPreviewViewController *vc = [[UIStoryboard storyboardWithName:@"MyCharteredBus" bundle:nil] instantiateViewControllerWithIdentifier:@"EditCharteredOrderPreviewViewController"];
    vc.hidesBottomBarWhenPushed = YES;
    vc.charteredBusType = self.charteredBusType;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
